import Vue from "vue";
import Main from "./historydrawer.vue";
import { Drawer } from "element-ui";
import router from "../../../router";

if (typeof window !== 'undefined' && window.Vue) {
  Vue = window.Vue
}

Vue.use(Drawer);

//创建一个构造器
const HistoryConstructor = Vue.extend(Main);

//传入组件需要的参数
let historyDom=new HistoryConstructor({
  el:document.createElement('div'),
  data(){
    return{
      value:false
    }
  },
  router
})

function ShowHistory(){  
  //向body节点添加组件
  if(!historyDom.value){
    historyDom.value=true
    document.getElementById('app').appendChild(historyDom.$el);
  }
}

function DeleteHistory(){  
  //删除节点
  historyDom.value=false;
  document.getElementById('app').removeChild(historyDom.$el);
  historyDom=null;
}

//向vue实例添加方法
function historyRegistry(){
  Vue.prototype.$openHistory=ShowHistory;
  Vue.prototype.$closeHistory=DeleteHistory;
}

export default historyRegistry;

